package controllers

import "github.com/gin-gonic/gin"
import "net/http"
import "egoal.com/DistributionGo/application"

type UserController struct {
	UserAppService *application.UserAppService `inject:""`
}

func (u *UserController) UserIndex(c *gin.Context) {
	users, err := u.UserAppService.GetAllUsers()
	if err != nil {
		c.JSON(http.StatusOK, err)
	}
	c.JSON(http.StatusOK, users)
}

func (u *UserController) GetById(c *gin.Context) {
	id := c.PostForm("id")
	user, err := u.UserAppService.GetById(id)
	if err != nil {
		c.JSON(http.StatusOK, err)
	}
	c.JSON(http.StatusOK, user)
}

func (u *UserController) GetByUserName(c *gin.Context) {
	userName := c.PostForm("UserName")
	user, err := u.UserAppService.GetByUserName(userName)
	if err != nil {
		c.JSON(http.StatusOK, err)
	}
	c.JSON(http.StatusOK, user)
}
